<?php
// ----------------------------------------------------------------------
// pn-commerce Shopping Cart Solution for PostNuke
// http://pncommerce.de
// http://www.sourceforge.net/projects/pn-commerce/
//
// It is based on PostKart 0.701QA from
//			Destin LeBlanc [ postkart@zenflesh.com ]
// ----------------------------------------------------------------------
// Source file:  $Source: /cvsroot/pn-commerce/pn-commerce/pnpmaccounttransferapi.php,v $
//
// Last changes from:  $Author: landseer $
//
// Revision:           $Revision: 1.6 $
//
// Date of revision    $Date: 2004/09/12 15:17:32 $
//  
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------

require_once("modules/pncommerce/common.php");

/**
 * load the config array and return it
 * no arguments needed
 */
function pncommerce_pmaccounttransferapi_getConfig ($args=array())
{
    $data=pnModGetVar ('pncommerce', 'pmaccounttransferData');
    if(isset($data))
    {
        return unserialize($data);
    }
    return false;
}

/**
 * save the config array
 * @param $args array of config values
 */
function pncommerce_pmaccounttransferapi_setConfig ($args)
{
    pnModSetVar( 'pncommerce', 'pmaccounttransferData',serialize($args));
}


/**
 * Ask the user for necessary information for this payment method
 * NOT NECESSARY FOR ACCOUNT TRANSFER
 * ask the user for specific data for this paymethod, e.g. credit card data
 * if no special data is needed (e.g. check) we can return almost immediately
 * otherwise we will display an additional page and do the reponse checking also
 * For response checking  we call pncommerce_user_paymethodforward which will finally call the userinforesponse
 * function below
 * general stuff:
 * This function is used during the checkout process
 * you can let the user provide special information
 * you need for further processing
 * when you don't need any info just redirect the user to
 * getshippingmethod in the pnuser.php
 *
 * It's important to redirect to getshippingmethod if everything was ok here
 */
function pncommerce_pmaccounttransferapi_getdata ($args)
{
    // no need to ask for anything, just forward
    pnRedirect( pnModURL( 'pncommerce', 'user', 'getshippingmethod', $args ) );
    return true;
}

/**
 * Check if all information we need are supplied
 * This will be called from userinfo() via the stub function pncommerce_user_paymethodforwad()
 * NOT NECESSARY FOR ACCOUNTTRANSFER
 * This function is used during the checkout process
 * you can save the provide information here
 * getshippingmethod in the pnuser.php
 *
 */
 
function pncommerce_pmaccounttransferapi_getdataresponse($args)
{
}

/**
 * This function is used during the checkout process
 * it's called after the checkout where the user agrees to
 * buy the items, so you can do the rest here to finish the
 * payment process if possible. otherwise just redirect to the next step
 * called processshippingfinal
 */
function pncommerce_pmaccounttransferapi_processpayment ($args)
{ 
    pnRedirect( pnModURL( 'pncommerce', 'user', 'processshippingfinal', $args ) );
    return true;
}



/**
 * Insert user data in db table if existing
 * NOT NECESSARY FOR ACCOUNTTRANSFER
 */
function pncommerce_pmaccounttransferapi_userinsert()
{
}

/**
 * if data need to be copied from the users table to the orders table on issuing an order,
 * it will be done here
 * This will be called from userinfo() via the stub function pncommerce_user_paymethodforwad()
 * NOT NECESSARY FOR ACCOUNTTRANSFER
 * @param $args['KID'] customer id
 * @param $args['ON'] order number
 */
function pncommerce_pmaccounttransferapi_order($args)
{
}

/**
 * start the configuration of the paymethod
 * it will be done here
 * This will be called from userinfo() via the stub function pncommerce_user_paymethodforwad()
 * @param $args['Mode'] possible values: install, remove, activate, deactivate
 */
function pncommerce_pmaccounttransferapi_configintro()
{
	$Mode = pnVarCleanFromInput ('Mode');
	if (!pnModAPILoad( 'pncommerce', 'user'))
    {
        return showerrorpage("unable to load pnuserapi", __FILE__, __LINE__);
    }
	if (pnSecAuthAction(0, '::', '::', ACCESS_ADMIN))
	{
	    switch ($Mode)
	    {
	    case 'install':
	    	$default=array( 'PMCalcFunc'=>'PMCFlat',
	    		            'PMCFlatPrice' => '0',
                            'AccountInfo'=>_PNC_NOACCOUNTINFO );
	    	pncommerce_pmaccounttransferapi_setConfig($default);
	    	pnModSetVar ('pncommerce', 'pmaccounttransfer', 'on');
	    	break;
	    case 'remove':
            pnModDelVar( 'pncommerce', 'pmaccounttransfer');
            pnModDelVar( 'pncommerce', 'pmaccounttransferData');
	    	break;
	    case 'activate':
	    	pnModSetVar ('pncommerce', 'pmaccounttransfer', 'on');
	    	break;
	    case 'deactivate':
	    	pnModSetVar ('pncommerce', 'pmaccounttransfer', 'off');
	    	break;
	    default:
	    	break;
	    }
       	pnRedirect( pnModAPIFunc('pncommerce','user','pncModURL',
								array('Module'=>'pncommerce', 'Section'=> 'admin', 'Function'=>'paymethodconfig')));
        return true;
    }
	else
	{
		return showerrorpage(_PNC_NOAUTH, __FILE__, __LINE__ );
	}
}

/**
 * showoption
 *
 */
function pncommerce_pmaccounttransferapi_showoption($args)
{
    extract ($args);
    $temp ="<input type='radio' name='PayMethod' value='pmaccounttransfer'";
    if ( $BPM == 'pmaccounttransfer' )
    {
        $temp .= " checked ";
    }
    $temp .= ">"._PNC_ACCOUNTTRANSFERORMONEYORDER."<br>";
    return $temp;
}

function pncommerce_pmaccounttransferapi_info ()
{
    return (_PNC_ACCOUNTTRANSFERORMONEYORDER);
}

function pncommerce_pmaccounttransferapi_footermsg ($args)
{
    extract ($args);
    $config=pncommerce_pmaccounttransferapi_getConfig();	
    $temp = ""._PNC_ACCOUNTTRANSFERORMONEYORDER.". <br>"
            ._PNC_WEWILLSHIPUPONPAYMENT.". <br>";
    $temp .= ""._PNC_MAKEACCOUNTTRANSFERPAYABLETO." ".$config['AccountInfo'].". <br>";
    return $temp;
}

/**
 * This function is used during the checkout process
 * You can calculate a fee for the selected paymethod here
 *
 * @param $args['SubTotal'] Double the total costs with shipping included
 * @return double 
 * @returns the fee for this paymethod
 */
function pncommerce_pmaccounttransferapi_getPaymethodTotal($args)
{
    //Return 0 = this Paymethod is for free
    if (!pnModAPILoad( 'pncommerce', 'user'))
    {
        return showerrorpage("unable to load pnuserapi", __FILE__, __LINE__);
    }
    $config=pncommerce_pmaccounttransferapi_getConfig();
    //add value to array to make the function able to calculate the fee
    $config['Value']=$args['SubTotal'];
    return pnModAPIFunc( 'pncommerce','user','getPMCalcValue',$config);
}

/**
 * Asks for special data for this paymethod, for example minimum fee or default fee, ...
 * Account numbers, ...
 * ****
 * You have to redirect to 'paymethodconfig' when you're done
 * ****
 * @return String 
 * @returns the config page for this paymethod
 */
function pncommerce_pmaccounttransferapi_config()
{
    if (!pnModAPILoad( 'pncommerce', 'admin'))
    {
        return showerrorpage("unable to load pnadminapi", __FILE__, __LINE__);
    }
    if (!pnModAPILoad( 'pncommerce', 'user'))
    {
        return showerrorpage("unable to load pnuserapi", __FILE__, __LINE__);
    }
 
    if (pnSecAuthAction(0, '::', '::', ACCESS_ADMIN))
    {
         
        $submit = pnVarCleanFromInput( 'submit' );
    
        if( !$submit )
        {
            $smarty = new pnRender( 'pncommerce' );
            $smarty->caching = false;
            $smarty->assign( 'config', pncommerce_pmaccounttransferapi_getConfig() );
            return $smarty->fetch( 'pncommerce_pmaccounttransfer_configuration.html' );
        }
        else    // submit is set
        {
    
    if( !pnSecConfirmAuthKey() ) 
    { 
        return showerrorpage( _PNC_BADAUTHKEY, __FILE__, __LINE__ ); 
    }     
    
            $storage=array();
            $storage['PMCalcFunc'] = pnVarCleanFromInput('PMCalcFunc');
            $storage['AccountInfo'] = pnVarCleanFromInput ('AccountInfo');
            $storage=pnModAPIFunc( 'pncommerce', 'user', 'gatherPMCalcData', $storage );
            pncommerce_pmaccounttransferapi_setConfig($storage);
            pnRedirect( pnModAPIFunc('pncommerce','user','pncModURL',
		      	        array( 'Module'=>'pncommerce', 
		      		           'Section'=> 'admin', 
		      		           'Function'=>'paymethodconfig' ) ) );
            return true; 
        }
        
    }
    return false;
}

?>
